package com.ruoyi.licence.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.licence.domain.Licence;
import com.ruoyi.licence.service.ILicenceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预售许可证列表Controller
 * 
 * @author ruoyi
 * @date 2024-09-14
 */
@RestController
@RequestMapping("/licence/licence")
public class LicenceController extends BaseController
{
    @Autowired
    private ILicenceService licenceService;

    /**
     * 查询预售许可证列表列表
     */
    @PreAuthorize("@ss.hasPermi('licence:licence:list')")
    @GetMapping("/list")
    public TableDataInfo list(Licence licence)
    {
        startPage();
        List<Licence> list = licenceService.selectLicenceList(licence);
        return getDataTable(list);
    }

    /**
     * 导出预售许可证列表列表
     */
    @PreAuthorize("@ss.hasPermi('licence:licence:export')")
    @Log(title = "预售许可证列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Licence licence)
    {
        List<Licence> list = licenceService.selectLicenceList(licence);
        ExcelUtil<Licence> util = new ExcelUtil<Licence>(Licence.class);
        util.exportExcel(response, list, "预售许可证列表数据");
    }

    /**
     * 获取预售许可证列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('licence:licence:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(licenceService.selectLicenceById(id));
    }

    /**
     * 新增预售许可证列表
     */
    @PreAuthorize("@ss.hasPermi('licence:licence:add')")
    @Log(title = "预售许可证列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Licence licence)
    {
        return toAjax(licenceService.insertLicence(licence));
    }

    /**
     * 修改预售许可证列表
     */
    @PreAuthorize("@ss.hasPermi('licence:licence:edit')")
    @Log(title = "预售许可证列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Licence licence)
    {
        return toAjax(licenceService.updateLicence(licence));
    }

    /**
     * 删除预售许可证列表
     */
    @PreAuthorize("@ss.hasPermi('licence:licence:remove')")
    @Log(title = "预售许可证列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(licenceService.deleteLicenceByIds(ids));
    }
}
